package com.example.NotePad;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

import android.app.ListActivity;
import android.content.Intent;
import android.util.Base64;
import android.view.MenuItem;
import android.view.View;
import android.widget.ListView;
import android.widget.SimpleAdapter;

/**
 * Basically this one is not in use, I just extract the functions from it and restructure the project
 * so just ignore this activity, and leave it for future use.
 * */
public class SetListView extends ListActivity{
	public static String[] ss = new String[100];
	private List<ListDetails> detailsList = null;
	ListDetails aListDetails = new ListDetails();
	
	
	private static final int GETLIST = 1;
	private static final int ABOUT = 2;
	private static final String LISTPATH ="/sdcard/1.txt";
	GetNoteListFunc aGetNoteListFunc = new GetNoteListFunc();
	
	private boolean myListViewHandler(MenuItem item){
		if(item.getItemId() == GETLIST)
		{
			//pressed Get List
			displayListView();
		}
		else if(item.getItemId() == ABOUT)
		{
			//pressed about
			
		}
		
		return super.onOptionsItemSelected(item);
	}
	
	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		// TODO Auto-generated method stub
		
		//check if the detailsList if has something in it
		if(detailsList != null){
			ListDetails detailListDetails = detailsList.get(position);
			Intent intent = new Intent();
			intent.putExtra("detail", detailListDetails.getNoteId());
//			intent.setClass(this, DetailActivity.class);
			startActivity(intent);
		}
		super.onListItemClick(l, v, position, id);
	}
	
	
	//is this public reasonable here? or I have to make another getter for it??
	public void displayListView(){
		List<ListDetails> listDetailsesDetails = aGetNoteListFunc.getNoteList();
		List<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
		for (Iterator iterator = listDetailsesDetails.iterator(); iterator.hasNext();) {
			ListDetails listDetails = (ListDetails) iterator.next();
			
			
			for(int i = 0; i<listDetailsesDetails.size(); i++){
			String decodeContentString = new String(listDetailsesDetails.get(i).getNoteContent());
			
//			String decodeContentString = new String(Base64.decode(aListDetails.getNoteName(), Base64.DEFAULT));
			
			HashMap<String, String> map = new HashMap<String, String>();
			map.put("notes_id", aListDetails.getNoteId());
			map.put("notes_name", decodeContentString);
			list.add(map);
			}
		}
		
		SimpleAdapter simpleAdapter = new SimpleAdapter(this, list, R.layout.details, new String[]{"notes_id","notes_name"}, new int[]{R.id.notes_id,R.id.notes_name});
		setListAdapter(simpleAdapter);
	};
}
